package cn.javaxc.mvcwork.modules.login;
import cn.javaxc.mvcwork.controller.MVCConstant;
import cn.javaxc.mvcwork.framework.actions.TActionContext;
import cn.javaxc.model.page.VUEFormBean;
import cn.javaxc.mvcwork.util.common.PasswordHash;
import org.springframework.stereotype.Component;
import org.springframework.context.annotation.Scope;
//import org.apache.shiro.authc.UsernamePasswordToken;

@Scope("prototype")
@Component("LoginBean")
public class LoginBean extends VUEFormBean {
  private String message = null;
  private String username = "";
  private String password = "";
  private String webdavPassword = "";
  private String ldapPassword = "";
  private String redirectTo = null;
  private String validatecode= null;
  private String passwordHash="";

  
  public LoginBean() { }

//  public LoginBean(UsernamePasswordToken token) {
//	username=token.getUsername();
//  	password=new String(token.getPassword());
//  }
  
  public void setUsername(String tmp) {
    this.username = tmp;
  }


  
  public void setPassword(String tmp) {
	if(tmp==null)return;
	tmp=tmp.trim();
	this.password = tmp;
	this.passwordHash = PasswordHash.encrypt(tmp);
    //Enrypt the webdav password. 'username' should be already set for a valid webdav password
    this.webdavPassword = PasswordHash.encrypt(username + ":" +MVCConstant.CFS_USER_REALM + ":" + tmp);
    this.ldapPassword = tmp;
  }

	
	public String getPasswordHash(){
		return this.passwordHash;
	}



  
  public void setMessage(String tmp) {
    this.message = tmp;
  }


  
  public String getUsername() {
    return username;
  }


  
  public String getPassword() {
    return password;
  }


  
  public String getMessage() {
    return message;
  }


  
  public String getWebdavPassword() {
    return webdavPassword;
  }

  public String getLdapPassword() {
    return ldapPassword;
  }

  public String getRedirectTo() {
    return redirectTo;
  }

  public void setRedirectTo(String redirectTo) {
    this.redirectTo = redirectTo;
  }

  public void checkURL(TActionContext context) {
    if (redirectTo == null) {
        String requestedURL = (String) context.getAttribute("requestedURL");
        if (requestedURL != null) {
          redirectTo = requestedURL;
        }
      }
  }
  

	public String getValidatecode(){
		return this.validatecode;
	}
	public void setValidatecode(String validatecode){
		this.validatecode=validatecode;
	}
	public String toString(){
		return message==null?super.toString():message;
	}
}
